import instance from '@/utils/axios'


function getChannelList() {
    return instance({
        url:'/v1_0/channels',
        method:"get",
    })
}
export { getChannelList }

function getArticleList({channel_id,timestamp}) {
    return instance({
        url:'/v1_0/articles',
        method:"get",
        params:{
            with_top:1,
            channel_id,
            timestamp
        }
    })
}

export { getArticleList }


function getArticleInfo(id) {
    /* 参数是文章id：直接在路径后面写(id作为路径一部分) 
        url/id
     */
    return instance({
        url:`/v1_0/articles/${id}`,
        method:'get',
    })
}
export { getArticleInfo }

//4.关注接口
//4.1 关注
function addFollowing(target){
    return instance({
        url:`/v1_0/user/followings`,
        method:'post',
        data:{target}
    })
}

//4.2 取消关注
function removeFollowing(target){
    /* 参数是用户id:直接在路径后面写(id作为路径一部分)
    格式： url/id
    */
    return instance({
        url:`/v1_0/user/followings/${target}`,
        method:'delete'
    })
}

export { addFollowing,removeFollowing }


// 5.1点赞接口
// 5.1点赞
function addLikings(target) {
    return instance({
        url:'/v1_0/article/likings',
        method:'post',
        data:{target}
    })
}

// 5.2取消点赞
function removeLikings(target) {
    /* 参数是用户id:直接在路径后面写(id作为路径一部分)
    格式:url/id
    */
    return instance({
        url:`/v1_0/article/likings/${target}`,
        method:'delete'
    })
}
export { addLikings,removeLikings } 


// 6.1不喜欢接口
// 6.1不喜欢
function addDisLikes(target) {
    return instance({
        url:'/v1_0/article/Dislikes',
        method:'post',
        data:{target}
    })
}

// 6.2取消不喜欢
function removeDisLikes(target) {
    /* 参数是用户id:直接在路径后面写(id作为路径一部分)
    格式:url/id
    */
    return instance({
        url:`/v1_0/article/Dislikes/${target}`,
        method:'delete'
    })
}
export { addDisLikes,removeDisLikes } 

// 7. 搜索框推荐词按钮
function getSuggestion(q) {
    return instance({
        url:'/v1_0/suggestion',
        method:'get',
        params:{q}
    })
}
export { getSuggestion }

// 8.搜索结果列表
function getSearchList({page,q}) {
    return instance({
        url:'/v1_0/search',
        method:'get',
        params:{
            per_page:10,
            page,
            q
        }
    })
}
export { getSearchList }